<?php

class TemplateLang extends TemplateParser
{

  protected function render()
  {
    global $config;

    $output = '';

    $locale = Account::getLocale();

    $filename = APP_DIR . '/language/' . $locale . '/' . $config['theme'] . '.php';

    if (file_exists($filename)) {
      //$lang = eval(file_get_contents($filename));
      require($filename);
    }
    else {
      $lang = array();
    }

    $str = sy_slugify($this->content) . '-' . md5($this->content);

    if (! isset($lang[$str])) {
      $lang[$str] = $this->content;

      $_lang = "<?php \$lang = array(\n";
      foreach ($lang as $k => $v) {
        $_lang .= "'$k' => '$v',\n";
      }
      $_lang .= ');';

      copy($filename, APP_DIR . '/language/' . $locale . '/' . $config['theme'] . '_' . time() . '.php');

      file_put_contents($filename, $_lang);
    }

    $output = $lang[$str];

    return $this->parseVars($output);
  }

}
